//
//  WYCCodeViewController.m
//  51信用卡
//
//  Created by 王晓民 on 2018/2/26.
//  Copyright © 2018年 中企互联. All rights reserved.
//

#import "WYCCodeViewController.h"
#import "WYCBillModel.h"
@interface WYCCodeViewController ()
{
    int  num;
}
@property(nonatomic,strong)UITextField * codeText;
@property(nonatomic,strong)NSMutableArray * lastArr;
@property(nonatomic,strong)NSMutableArray * cardArr;

@end

@implementation WYCCodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _lastArr =[[NSMutableArray alloc]init];
    _cardArr =[[NSMutableArray alloc]init];
    self.navigationItem.title = @"信用卡认证";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setBarTintColor:wycMain];
    self.view.backgroundColor =[UIColor whiteColor];
    [self creatMain];
    [self setupCreditcardlist];
}
-(void)creatMain
{
    NSLog(@"银行卡号%@",_cardNumber);
      NSString *str3 = [_cardNumber substringWithRange:NSMakeRange(_cardNumber.length-4, 4)];
    //赋值控件
    UILabel * bank = [[UILabel alloc] init];
    bank.frame = CGRectMake(20, 120,  ScreenWidth-40, 30);
    bank.text = [NSString stringWithFormat:@"%@(%@)",_strName,str3];
    bank.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:bank];
    
    UIView * bankview = [[UIView alloc] init];
    bankview.frame = CGRectMake(20,149,ScreenWidth-40, 0.5);
    bankview.backgroundColor = WYCgrayColor;
    [self.view addSubview:bankview];
    
    _codeText = [[UITextField alloc]initWithFrame:CGRectMake(20, 160, ScreenWidth-40, 30)];
    [_codeText setFont:[UIFont systemFontOfSize:15]];
    _codeText.placeholder =@"请输入验证码";
    _codeText.keyboardType = UIKeyboardTypeNumberPad;
    [self.view addSubview:_codeText];

    
    UIView * bankview1 = [[UIView alloc] init];
    bankview1.frame = CGRectMake(20,200,ScreenWidth-40, 0.5);
    bankview1.backgroundColor = WYCgrayColor;
    [self.view addSubview:bankview1];
    
    //提交按钮
    UIButton *SubmitButton = [[UIButton alloc] init];
    SubmitButton.frame = CGRectMake(40 * px,bankview1.frame.size.height+bankview1.frame.origin.y+40 , ScreenWidth - 80 * px, 150 * px);
    SubmitButton.layer.cornerRadius = 5;
    [SubmitButton addTarget:self action:@selector(pressREN) forControlEvents:UIControlEventTouchUpInside];
    SubmitButton.backgroundColor = WYCmainColor;
    [SubmitButton setTitle:@"提交" forState:UIControlStateNormal];
    [SubmitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:SubmitButton];
    
}


//提交
-(void)pressREN
{
    
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    params[@"valiNum"] = self.codeText.text;
    params[@"cardId"] = _strCard;
    params[@"token"] = [WYCAccountTool unarchivetoken];
    NSLog(@"传值%@",params);
    [HttpTool POST:confirmCreditAuthOrder params:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
           
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"认证成功"];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }else{
            
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msgStr];
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showImage:[UIImage imageNamed:@""] status:Failed];
    }];
    
}
#pragma make ------->>>列表请求
- (void)setupCreditcardlist{
    
    NSString *cardlist = [NSString stringWithFormat:@"%@token=%@",creditcardlist,[WYCAccountTool unarchivetoken]];
    [HttpTool POST:cardlist params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([[responseObject objectForKey:@"code"] intValue ] == 0) {
            
            NSArray * resultArray = responseObject[@"result"];
            NSLog(@"首页数据%@ %@",responseObject,resultArray);
            for (NSDictionary *dic in resultArray) {
                NSString  * lastNumber = dic[@"lastNumber"];
                [_lastArr addObject:lastNumber];
                NSString  * cardId = dic[@"cardId"];
                [_cardArr addObject:cardId];
            }
        }else{
            
            [self showToast:msgStr];
            
        }
        
       
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
        [self showToast:Failed];
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
